<?php


namespace encrypt;



class Aes
{



    public static function getKey($key){
        return hash('sha256', $key, true);
    }

    public static function encrypt($input,$key)
    {
        $data = openssl_encrypt($input, 'AES-256-CBC',self::getKey($key), OPENSSL_RAW_DATA, self::hexToStr());
        $data = base64_encode($data);
        return $data;
    }

    public static function decrypt($input,$key)
    {
        $decrypted = openssl_decrypt(base64_decode($input), 'AES-256-CBC', self::getKey($key), OPENSSL_RAW_DATA, self::hexToStr());
        return $decrypted;
    }




    public static function  hexToStr($hex =  '00000000000000000000000000000000')
    {

        $string='';

        for ($i=0; $i < strlen($hex)-1; $i+=2)

        {

            $string .= chr(hexdec($hex[$i].$hex[$i+1]));

        }

        return $string;
    }


}

